package com.googlecode.totallylazy.parser;

import com.googlecode.totallylazy.Segment;

import java.util.concurrent.atomic.AtomicReference;

public class Reference<A> extends Parser<A> {
    private final AtomicReference<Parser<A>> reference = new AtomicReference<Parser<A>>();

    @Override
    public String toString() {
        return reference.get().toString();
    }

    @Override
    public Result<A> parse(Segment<Character> sequence) throws Exception {
        return reference.get().parse(sequence);
    }

    public Reference<A> set(Parser<A> parser){
        reference.set(parser);
        return this;
    }
}
